#!/usr/bin/sh

modprobe cuberevo_micom paramDebug=50

if [ -e /var/etc/.firstboot ]; then
   rm /var/etc/.firstboot
   sleep 1
   echo "WAIT 3 min"
   echo "WAIT 3 min" >/dev/vfd
   touch /dev/.devfsd
fi

if [ -e /etc/init.d/mountvirtfs ]; then
   /etc/init.d/mountvirtfs start
fi

if [ -e /dev/ttyAS1 ]; then 
   rm -f /dev/ttyAS1 
fi 

if [ -e /etc/init.d/portmap ]; then
   /etc/init.d/portmap start
fi

modprobe e2_proc

# start automounter with umount timeout of 5 seconds
modprobe autofs4
/usr/sbin/automount --timeout=5 /autofs file /etc/auto.usb

if [ ! -e /var/etc/.firstboot ]; then
   echo "LOADING MODULES" > /dev/vfd
   echo "LOADING MODULES"   

   echo "Starting DEBUG Interface"
if [ -e /etc/init.d/mountall ]; then
   /etc/init.d/mountall start
fi

   fp_control -c

   echo "init stmfb"
   modprobe stmcore-display-stx7109c3
   /usr/bin/eeprom tvmode
   TVMODE=$?
   case "$TVMODE" in
	0) echo "SD-PAL"
  	   modprobe stmfb display0=720x576-32@50:12m:pal:yuv:yuv;;
	1) echo "SD-NTSC"
	   modprobe stmfb display0=720x480-32@60:12m:ntsc-m:yuv:yuv;;
	2) echo "720P-50"
	   modprobe stmfb display0=1280x720-32@50:12m:pal:yuv:yuv;;
	3) echo "720P-60"
	   modprobe stmfb display0=1280x720-32@60:12m:ntsc-m:yuv:yuv;;
	4) echo "1080I-50"
	   modprobe stmfb display0=1920x1080-32@50i:12m:pal:yuv:yuv;;
	5) echo "1080I-60"
	   modprobe stmfb display0=1920x1080-32@60i:12m:ntsc-m:yuv:yuv;;
	*) echo "Use default SD-PAL"
	   modprobe stmfb display0=720x576-32@50:12m:pal:yuv:yuv;;
   esac

   echo "init AVS"
   modprobe avs type=stv6412

   echo "load a/v firmware"
   /usr/bin/ustslave /dev/st231-1 /boot/audio.elf
   /usr/bin/ustslave /dev/st231-0 /boot/video.elf

   echo "init embx"
   modprobe embxshell
   modprobe embxmailbox mailbox0=0xb9211000:136:set2 mailbox1=0xb9212000:0 ;
   modprobe embxshm mailbox0=shm:0:7:0x60000000:0:256:256:0:512:0xa4000000:0x10000000 ;
   modprobe mme_host transport0=shm

   echo "init player"
   modprobe mmelog
   modprobe mpeg2hw mmeName=MPEG2_TRANSFORMER1;
   modprobe ksound
   modprobe p2div64
   modprobe stm_v4l2
   modprobe pseudocard

   modprobe frontend_platform
   modprobe socket
   modprobe lnbh221
   modprobe lnb_pio

   if [ -f /lib/modules/2.6.32.71_stm24_0217/extra/dvb-pll ]; then
       modprobe dvb-pll
   fi

   if [ -f /lib/modules/2.6.32.71_stm24_0217/extra/cx24116 ]; then
       modprobe cx24116
   fi

   if [ -f /lib/modules/2.6.32.71_stm24_0217/extra/tda10023 ]; then
       modprobe tda10023
   fi

   if [ -f /lib/modules/2.6.32.71_stm24_0217/extra/zl10353 ]; then
       modprobe zl10353
   fi

   if [ -f /lib/modules/2.6.32.71_stm24_0217/extra/stv090x ]; then
       modprobe stv090x
   fi

   if [ -f /lib/modules/2.6.32.71_stm24_0217/extra/stv0288 ]; then
       modprobe stv0288
   fi

   modprobe starci

   # Full feature pti
   modprobe pti waitMS=20 videoMem=4096
   if [ $?=='2' ]; then
      # Simple pti
      modprobe pti
   fi
   modprobe stm_monitor
   modprobe stmsysfs
   modprobe stmdvb

   modprobe player2
   modprobe sth264pp
   modprobe stmalloc
   modprobe platform
   modprobe silencegen 

   showiframe -p /usr/share/bootlogo.mvi &
   stfbcontrol a 0

   echo "init frontpanel"
   modprobe simu_button

   mknod /dev/rc c 147 1 

   #params:
   #period
   #delay
   /usr/bin/evremote2 10 140 &

   stfbcontrol a 255

if [ -e /etc/init.d/mountall ]; then
   /etc/init.d/mountall start
fi

if [ -e /etc/init.d/vsftpd ]; then
   /etc/init.d/vsftpd start
fi
   /usr/sbin/inetd

   echo "LOADING e2" > /dev/vfd
   echo "LOADING e2"

   until false
   do
      echo "starting e2->"
      /usr/bin/enigma2
      rtv=$?
      echo "e2 ended <- RTV: " $rtv
      case "$rtv" in
		0) echo "0"
		   echo "E2 ERROR"
      	   init 6;;
		1) echo "1"
		   echo "SHUTDOWN"
		   init 0;;
		2) echo "2"
		   echo "REBOOT"
		   fp_control -r 00:00:00 01.01.1980;;
		3) echo "3"
		   echo "E2 RESTART"
		   echo "0" > /proc/progress
		   showiframe -p /usr/share/bootlogo.mvi &;;
		*) echo "*"
		   echo "ERROR"
		   fp_control -r 00:00:00 01.01.1980;;
      esac
   done 
fi
